﻿using System;
using System.Collections.Generic;

namespace HobSoft.SoccerBet2014.Wcf
{
    using Domain.ClientService;
    using Domain.Common.SiteContext;
    using Domain.Implementation;
    using Domain.IRepositories;
    using Domain.Models;
    using Domain.Models.Site;

    public class SystemService : ISystemService
    {
        private readonly IBookmakerRepository bookmakerRepository;
        private readonly ICookiesManager cookieManager;
        private readonly ISiteContextRepository siteContextRepository;
        public SystemService(IBookmakerRepository _bookmakerRepository,
                                        ICookiesManager _cookieManager,
                                        ISiteContextRepository _siteContextRepository)
        {
            bookmakerRepository = _bookmakerRepository;
            cookieManager = _cookieManager;
            siteContextRepository = _siteContextRepository;
        }

        public IList<Bookmaker> GetBookmaker()
        {
            return bookmakerRepository.GetMany(b => b.Available);
        }

        public bool Signup(string user, string password)
        {
            throw new NotImplementedException();
        }

        public void SubmitCookies(IList<AccountCookie> cookies)
        {
            var redisCookies = cookieManager as ReadWriteRedisRepository<AccountCookie>;
            if (redisCookies != null && cookies.Count > 0)
            {
                redisCookies.AddOrUpdate(cookies);
            }
        }

        public void SubmitSiteContext(IList<SiteContext> siteContext)
        {
            var redisSiteContext = siteContextRepository as ReadWriteRedisRepository<SiteContext>;
            if (redisSiteContext != null && siteContext.Count > 0)
            {
                redisSiteContext.AddOrUpdate(siteContext);
            }
        }
    }
}
